package sort;

/**
 * @author yunfei.shang
 * @date 2017/5/31.
 * @descreption 选择排序实现方式
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] baseArray = {10, 1, 8, 6, 4, 6, 3, 5, 9};
        selectSortOne(baseArray);
    }

    /**
     * 正向选择排序
     *
     * @param baseArray
     */
    public static void selectSortOne(int[] baseArray) {
        int pos = 0;
        for (int i = 0; i < baseArray.length - 1; i++) {
            pos = i;
            for (int j = i + 1; j < baseArray.length; j++) {
                if (baseArray[pos] > baseArray[j]) {
                    pos = j;
                }
            }
            int temp = baseArray[i];
            baseArray[i] = baseArray[pos];
            baseArray[pos] = temp;
        }
        for (int i : baseArray) {
            System.out.println(i);
        }
    }
}
